package com.hotel.room.controller;

import cn.hutool.core.convert.NumberWithFormat;
import com.hotel.common.config.SystemConfig;
import com.hotel.common.util.JwtUtil;
import com.hotel.common.vo.R;
import com.hotel.room.service.HotelRoomCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author trc
 * @since 2024-06-17
 */
@RestController
@RequestMapping("/hotel/roomCollect")
public class HotelRoomCollectController {

    @Autowired
    private HotelRoomCollectService hotelRoomCollectService;

    @RequestMapping("/change")
    public R changeRoomCollect(@RequestParam("collectStatus") Integer collectStatus, @RequestParam("roomId") Integer roomId, HttpServletRequest request) {

        // 从token中获取用户id
        String token = request.getHeader(SystemConfig.HEADER_TOKEN);
        Integer id = ((NumberWithFormat) JwtUtil.parseToken(token,"id")).intValue();
        return hotelRoomCollectService.changeRoomCollect(collectStatus, roomId, id);
    }

    @RequestMapping("/getStatus")
    public R selectRoomCollect(@RequestParam("roomId") Integer roomId, HttpServletRequest request) {

        // 从token中获取用户id
        String token = request.getHeader(SystemConfig.HEADER_TOKEN);
        Integer id = ((NumberWithFormat) JwtUtil.parseToken(token,"id")).intValue();
        return hotelRoomCollectService.selectRoomCollect(roomId, id);

    }

    @RequestMapping("/show")
    public R showUserCollectRoom(HttpServletRequest request) {

        // 从token中获取用户id
        String token = request.getHeader(SystemConfig.HEADER_TOKEN);
        Integer id = ((NumberWithFormat) JwtUtil.parseToken(token,"id")).intValue();
        return hotelRoomCollectService.showUserCollectRoom(id);

    }

}

